<?php
/**
 * 	个人中心
 *  author： chengda
 *  date  ： 2017-12-07
 */
namespace Admin\Controller;

class CenterController extends AbstractController  {

	protected $From;

	public function _initialize(){
		$this->From = D('user');
    }
	

    public function index(){
    	$userInfo=session();
    	$username=$userInfo['USER']['TrueName'];
    	$userID=$userInfo['USER_ID'];
    	// 顶部状态sql
    	$sql1='SELECT COUNT(*) AS TaskCount FROM task WHERE IsDel=0 AND `Status`!=1 AND  UserID='.$userID;
    	$sql2='SELECT COUNT(*) AS ProjectCount FROM project WHERE IsDel=0 AND InputUserID='.$userID;
    	$sql3='SELECT COUNT(*) AS ContractCount FROM contract WHERE IsDel=0 AND UserID='.$userID;
    	$sql4='SELECT COUNT(*) AS weekreportCount FROM weekreport WHERE IsDel=0 AND UserID='.$userID;//周统计
    	$sql5='SELECT COUNT(*) AS monthreportCount FROM monthreport WHERE IsDel=0 AND UserID='.$userID;//月统计
    
    	$a1=$this->From->query($sql1);
    	$a2=$this->From->query($sql2);
    	$a3=$this->From->query($sql3);
    	$a4=$this->From->query($sql4);
    	$a5=$this->From->query($sql5);

    	$data['TaskCount']=$a1[0]['TaskCount']?$a1[0]['TaskCount']:0;
    	$data['ProjectCount']=$a2[0]['ProjectCount']?$a2[0]['ProjectCount']:0;
    	$data['ContractCount']=$a3[0]['ContractCount']?$a3[0]['ContractCount']:0;
    	$data['weekreportCount']=$a4[0]['weekreportCount']?$a4[0]['weekreportCount']:0;
    	$data['monthreportCount']=$a5[0]['monthreportCount']?$a5[0]['monthreportCount']:0;

    	//每月参与的项目数量
    	$year=date("Y");//今年
    	$sql6="select DATE_FORMAT(InputTime,'%m') as month,COUNT(*) as count  from project  where DATE_FORMAT(InputTime,'%Y')=".$year." group by month  order by month";

		$a6=$this->From->query($sql6);
		//var_dump($a6);
		for ($i=1; $i <=12 ; $i++) { 
			$arr[$i]=0;
			foreach ($a6 as $key => $value) {
				if($value['month']==$i){
					$arr[$i]=$value['count'];
				}
			}
		}
		//var_dump(implode(",",$arr));
		//任务分布情况
		//0 办理之中  1 未办理
		$sql7='SELECT status,COUNT(*) AS count FROM task where UserID='.$userID.' GROUP BY status';		

		$a7=$this->From->query($sql7);
		$bdata['blzz']=0;
		$bdata['wbl']=0;
		foreach ($a7 as $key => $value) {
			if($value['status']==0){
				$bdata['blzz']=$value['count'];
			}elseif($value['status']==1){
				$bdata['wbl']=$value['count'];
			}
		}
		//var_dump($bdata); exit();
    	$this->assign("username",$username);
    	$this->assign("data",$data);
    	$this->assign("monthdata",implode(",",$arr));
    	$this->assign("bdata",$bdata);
        $this->display();
    }


}